<style>
.product_img img {
	border: solid 3px #fff;
	margin-right: 5px;
}
.product_img img.hover {
	border-color: #ff8800;
}
.product_img img.current {
	border-color: #df0001;
}
</style>
<div class="container bm-page">
  <div class="col-md-8">
    <div class="bm-form-container" >
      <div class="crumbs-box">
        <div class="crumbs bm-spt"></div>
      </div>
      <div class="form-box">
        <div class="bm-tabs"> <a href="<?php echo YzwController::U('bm') ?>" class="pull-left btn tb-btn "><i class="bm-spt"></i>天猫、淘宝商品报名</a> <a href="<?php echo YzwController::U('jd') ?>" class="pull-left btn jd-btn active"><i class="bm-spt"></i>京东商城商品报名</a>
          <div class="clearfix"></div>
        </div>
        <form id="goodsbm" action="<?php echo YzwController::U('jd') ?>" method="post">
          <table class="form">
            <tbody>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model,'detail_url'); ?>：</td>
                <td><input type="text" name="detail_url" class="input input-mid" value="<?php echo $data['detail_url'] ?>" id="detail_url" placeholder="请填写商品京东商品地址"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model,'goods_name'); ?>：</td>
                <td><input type="text" class="input input-big" name="goods_name" value="<?php echo $data['goods_name'] ?>" id="goods_name" maxlength="15" placeholder="标题最短不能少于7个，最长不能大于10个"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model,'cat_id'); ?>：</td>
                <td><select name="cat_id">
                    <option value="">请选择商品分类</option>
                    <?php echo CategoryModel::model()->htmlCategorySelectOption($data['cat_id']) ?>
                  </select></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model,'p_price'); ?>：</td>
                <td><input type="text" class="input input-sm" id="p_price" name="p_price" value="<?php echo $data['p_price'] ?>"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model,'promo_price'); ?>：</td>
                <td><input type="text" class="input input-sm" name="promo_price" id="promo_price" value="<?php echo $data['promo_price'] ?>"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model,'sales'); ?>：</td>
                <td><input type="text" class="input input-sm" name="sales" id="sales" value="<?php echo $data['sales'] ?>"></td>
              </tr>
              <tr>
                <td class="title">联系旺旺：</td>
                <td><input type="text" class="input input-sm" name="nick" id="nick"  value="<?php echo $data['nick'] ?>" placeholder="联系旺旺"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model,'product_img'); ?>：</td>
                <td><input type="text" class="input input-big" name="product_img" id="product_img" value="<?php echo $data['product_img'] ?>" placeholder="http://">
                  <div class="trip">*图片规定尺寸大小300*300，图片使用清新背景图，模特浅底图，除品牌logo以外不能有其他字眼，请按要求来，否则不予通过。</div></td>
              </tr>
              <tr>
                <td class="title"></td>
                <td><div class="product_img"> </div></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model,'goods_brief'); ?>：</td>
                <td><textarea name="goods_brief" style=" width:483px; height:100px;" placeholder="商品简介不能少于25个字"><?php echo $data['goods_brief'] ?></textarea></td>
              </tr>
              <tr>
                <td class="title"></td>
                <td><input type="hidden" name="state" value="<?php echo $data['state'] ?>" id="state">
                  <input type="hidden" name="city" value="<?php echo $data['city'] ?>" id="city">
                  <input type="hidden" name="brand_id" value="<?php echo $data['brand_id']?$data['brand_id']:0 ?>" id="brand_id">
                  <input type="hidden" name="commission_rate" id="commission_rate" value="<?php echo $data['commission_rate']?$data['commission_rate']:0 ?>">
                  <input type="hidden" name="listorder" value="<?php echo $data['listorder']?$data['listorder']:100 ?>">
                  <input type="hidden" name="level" id="level" value="<?php echo $data['level']?$data['level']:1 ?>">
                  <input type="hidden" name="item_type" id="item_type" value="<?php echo $data['item_type']?$data['item_type']:0 ?>">
                  <input type="hidden" id="credit_score" value="0">
                  <input type="hidden" id="seller_credit_score" value="6">
                  <input class="bm-btn bm-spt" type="submit" value=""></td>
              </tr>
            </tbody>
          </table>
        </form>
        <div class="bottom"> 已经有报名的商品，<a href="<?php echo YzwController::U('user/goodsbm/goods') ?>">点击查询报名情况</a>! </div>
      </div>
    </div>
  </div>
  <?php include $this->getViewFile('/goodsbm/statement'); ?>
  <div class="clear"></div>
  <?php include $this->getViewFile('/lib/login_and_reg'); ?>
</div>
<?php include $this->getViewFile('/goodsbm/container'); ?>
<script src="<?php echo Yii::app()->params->staticUrl; ?>statics/js/ajaxForm.js"></script> 
<link rel="stylesheet" href="<?php echo Yii::app()->params->staticUrl; ?>statics/js/artDialog6/css/ui-dialog.css">
<script src="<?php echo Yii::app()->params->staticUrl; ?>statics/js/artDialog6/js/dialog-min.js"></script>
<script>
var tips = dialog();
//防止一次提交多条
var locking = false;

function product_img() {
    $('div.product_img img').click(function() {
        $('div.product_img img').removeClass('current');
        $(this).addClass('current');
        $('#product_img').val(this.src);
    });
}

function getInfo() {
    var product_id = $('input[name="detail_url"]').val();
    if (product_id == '') {
        return false;
    }
    $.getJSON('<?php echo YzwController::U('iteminfo') ?>', {product_id: product_id}, function(data) {
            if (data.status) {
                $('#detail_url').val(data.detail_url);
                $('#goods_name').val(data.title);
                //原价
                $('#p_price').val(data.p_price);
                $('input[name="p_price"]').val(data.p_price);
                //活动价格
                $('#promo_price').val(data.promo_price);
                //商品ID
                $('#product_id').val(data.product_id);
                $('input[name="product_id"]').val(data.product_id);
                //旺旺
                //$('input[name="nick"]').val(data.nick);
                //店铺类型
                $('input[name="item_type"]').val(data.item_type);
                //销量
                $('#sales').val(data.sales);
                //店铺等级
                $('#credit_score').val(data.credit_score);
                //图片
                var imgstr = '';
                if (data.images) {
                    $.each(data.images, function(i, v) {
                        if (i == 0) {
                            $('#product_img').val(v);
                            imgstr += '<img class="current" width="160" height="160" src=' + v + ' />';
                        } else {
                            imgstr += '<img  width="160" height="160"  src=' + v + ' />';
                        }
                    });
                    $('div.product_img').html(imgstr);
                    product_img();
                }
            }
        });
}

//登录
function login(){
	$('div.login_reg_page').show();
	$('#login-form').ajaxForm({
		dataType: 'json',
		url:'<?php echo YzwController::U('login') ?>',
		success:function(data){
			if(data.status){
				$('#login-form').clearForm();
				$('div.login_reg_page').hide();
				$('#goodsbm').submit();
			}else{
				var d = dialog({
					title: '提示',
					content: data.info,
					cancel: false,
					okValue:'确定',
					ok: function () {}
				});
				d.show();
			}
		}
	});
	$('#login-regmobile').ajaxForm({
		dataType: 'json',
		success:function(data){
			if(data.status){
				$('#login-form').clearForm();
				$('div.login_reg_page').hide();
				$('#goodsbm').submit();
			}else{
				var d = dialog({
					title: '提示',
					content: data.info,
					cancel: false,
					okValue:'确定',
					ok: function () {}
				});
				d.show();
			}
		}
	});
}

$(function() {
    $('#goodsbm').ajaxForm({
        dataType: 'json',
        beforeSubmit: function(data, obj, es) {
            if (locking) {
                alert('服务器已经在提交中，等待服务器处理结果，请稍后！');
                return false;
            }
			//图片大小
			var image = new Image();
			if($('#product_img').val() == ''){
				alert('商品图片不能为空！');
				return false;
			}
			image.src = $('#product_img').val();
			var height = image.height; 
			var width = image.width;
			if(height/width < 0.95){
				alert('图片的尺寸不符合，请使用正方形图片！');
				return false;
			}
            tips = dialog({
                fixed: true,
                title: '提交中...',
                cancelDisplay: false
            }).showModal();
            locking = true;
            return true;
        },
        success: function(data) {
			locking = false;
			if(data.info == 'not_logged'){
				tips.close();
				login();
				return true;
			}
            tips.title('系统提示');
			tips.content(data.info);
			tips.button([{
				value: '确定',
				callback: function () {
					 if (data.status) {
                        $('#goodsbm').clearForm();
                        $('div.product_img').html('');
                    }
					if (data.url) {
						window.location.href = data.url;
                    }
					return true;
				},
				autofocus: true
			}]);
        }
    });
    $('#get_good').click(function() {
        //getInfo();
    });
    $('input[name="detail_url"]').change(function() {
        //getInfo();
    });
});
</script>